/**
 * 填充投注记录列表
 */
function setBetRecordList(np=''){
	// 获取筛选信息
	var limit_day   = '';
	var qujian_day  = '';
	switch($('#tag_search_time a[class="userSearch time active"]').index().toString()){
		case '0':
			limit_day = resData.pageSuport.today;
			break;
		case '1':
			limit_day   = resData.pageSuport.yesterday;
			qujian_day  = resData.pageSuport.today;
			break;
		case '2':
			limit_day = resData.pageSuport.week;
			break;
	}
	var limit_status = '';
	switch($('#tag_search_status a[class="userSearch time active"]').index().toString()){
		case '0':
			limit_status = '0';
			break;
		case '1':
			limit_status = '1';
			break;
		case '2':
			limit_status = '2';
			break;
		case '3':
			limit_status = '3';
			break;
	}
	//彩票彩种过滤
	var choice_lott = $('#id_all_lottery').val();
	var get_day = $('#tag_search_time a[class="userSearch time active"]').index();
	// 总投注金额
	var bet_all_money       = 0;
	// 中奖金额
	var winner_money_amount = 0;
	// 盈利金额
	var yingli_money        = 0;
	// 标识投注内容太长
	var tolong = '';
	// 初始化列表
	$('#id_record_list').html('');
	var c_time = '';
	item_index = 0;
	var b_item_index = parseInt(page_limit) * ( parseInt($('#id_page_box li[class="tag_page_item active"]').attr('ami')) - 1);
	var e_item_index = 0;
	b_item_index = b_item_index ? b_item_index : 0;
	var reverseData = [];
	$.each(resData.orderMain, function (i, v){
		reverseData.unshift(v);
	})
	$.each(reverseData, function (i, v){
		c_time = parseInt(v.createtime);
		// 这里，PC版快三（时时彩不确定）没有写入betting_str字段，这里被跳过了， 现在暂时放开
		
		if(c_time < limit_day) return true;
		
		if(qujian_day != '' && c_time > qujian_day){
			return true;
		}
		
		switch(limit_status){
			case '1':
				// 已中奖
				if(v.status.toString() != 2) return true;
				break;
			case '2':
				// 未中奖
				if(v.status.toString() != 1) return true;
				break;
			case '3':
				// 等待开奖
				if(v.status.toString() != 0) return true;
				break;
			default:
				break;
		}
		console.log(choice_lott)
		if(choice_lott != '0' && choice_lott != v.lott_id) return true;
		console.log(22222)
		bet_all_money       += parseFloat(v.amount);
		winner_money_amount += parseFloat(v.prize);
		if(item_index > (b_item_index + page_limit) || 
				item_index < b_item_index) {
			item_index++;
			return true;
		}
		tolong = 'display: none;';
		if(v.code.length > 20) tolong = 'display: block;';
		var tr  = '<tr style="font-size: 12px;">';
		tr      += '	<td style="color: rgb(74, 169, 219);font-size:12px;">' + v.lottTitle + '</td>';
		tr      += '	<td style="font-size:12px;">' + v.period + '</td>';
		tr      += '	<td style="font-size:12px;"><div class="betNum">' + v.code + '</div><a href="javascript:void(0);" href="javascript:void(0);" amv="' + v.code + '" class="NumLink tag_show_bettingStr_more" style="width: 40px; line-height: 37px; color: rgb(74, 169, 187); ' + tolong + ' float: right;">[详情]</a></td>';
		tr      += '	<td style="font-size:12px;">' + v.amount + '</td>';
		tr      += '	<td style="font-size:12px;"><div class="betNum">' + (v.kj_code ? v.kj_code : '-----') + '</div><a href="javascript:void(0);" href="javascript:void(0);" class="NumLink" style="color: rgb(74, 169, 187); display: none;">[详情]</a></td>';
		if(parseInt(v.prize_amount) > 0){
			tr      += '	<td style="color: rgb(228, 57, 60);">' + v.prize + '</td>';
		}else{
			tr      += '	<td style="color: rgb(102, 102, 102);font-size: 12px;">' + (v.kj_code ? v.prize : '等待开奖') + '</td>';
		}
		tr      += '	<td style="font-size: 12px;line-height:12px;">' + v.date_createtime + '</td>';
		tr      += '	<td style="font-size:12px;"><a href="javascript:void(0);" href="javascript:void(0);" href="javascript:void(0);" class="alink tag_see_more" amv="' + v.item_id + '">查看</a></td>';
		
		tr 		+= '</tr>';
		$('#id_record_list').append(tr);
		item_index++;
	})
	createPage(np, item_index);
	$('#id_all_count').html(item_index);
	$('#id_summary span').eq(0).html(bet_all_money.toFixed(2) + '元');
	$('#id_summary span').eq(1).html(winner_money_amount.toFixed(2) + '元');
	$('#id_summary span').eq(2).html(parseFloat(winner_money_amount-bet_all_money).toFixed(2) + '元');
}

function setSeekOrderList(np=''){
	// 获取筛选信息
	var limit_day   = '';
	var qujian_day  = '';
	switch($('#tag_search_time a[class="userSearch time active"]').index().toString()){
		case '0':
			limit_day = resData.pageSuport.today;
			break;
		case '1':
			limit_day   = resData.pageSuport.yesterday;
			qujian_day  = resData.pageSuport.today;
			break;
		case '2':
			limit_day = resData.pageSuport.week;
			break;
	}
	var limit_status = '';
	switch($('#tag_search_status a[class="userSearch time active"]').index().toString()){
		case '0':
			limit_status = '-1';
			break;
		case '1':
			limit_status = '2';
			break;
		case '2':
			limit_status = '1';
			break;
		case '3':
			limit_status = '0';
			break;
	}
	var choice_lott = $('#id_all_lottery').val();
	
	// 总投注金额
	var bet_all_money       = 0;
	// 中奖金额
	var winner_money_amount = 0;
	// 盈利金额
	var yingli_money        = 0;
	// 初始化列表
	$('#id_record_list').html('');
	item_index = 0;
	var c_time = '';
	$.each(resData.data.mainList, function (i, v){
		if($.isEmptyObject(v)) return true;
		c_time = parseInt(v.createtime);
		// 获取追号数据的第一个期号信息
		var b_item = resData.data.itemList[v.id].pop();
		// 获取追号数据的最后一个期号信息
		var e_item = resData.data.itemList[v.id].shift();
		if(c_time < limit_day) return true;
		if(qujian_day != '' && c_time > qujian_day){
			return true;
		}
		if(limit_status != '-1') {
			if(limit_status == 2 && parseInt(b_item.winner) >= 1)return true;
			if(limit_status == 1 && (parseInt(b_item.winner) < 1 && parseInt(e_item.winner) < 1) )return true;
			if(limit_status == 0 && (parseInt(b_item.winner) < 1 || parseInt(e_item.winner) < 1))return true;
		}
		if(choice_lott != '0' && choice_lott != v.lott_id) return true;
		var tr  = '<tr style="font-size: 12px;">';
		tr      += '	<td style="color: rgb(74, 169, 219);font-size:12px;">' + v.order_no + '</td>';
		tr      += '	<td style="font-size:12px;">' + resData.lottIdKey[v.lott_id].title + '</td>';
		tr      += '	<td style="font-size:12px;">' + b_item.period + '</td>';
		tr      += '	<td style="font-size:12px;">' + v.open_times + '/' + v.item_times + '</td>';
		tr      += '	<td style="font-size:12px;">' + v.was_bet_money + '/' + v.amount + '</td>';
		if(parseInt(v.prize_amount) > 0){
			tr      += '	<td style="color: rgb(228, 57, 60);">' + v.prize_amount + '</td>';
		}else{
			tr      += '	<td style="color: rgb(102, 102, 102);font-size: 12px;">' + (v.kj_code ? v.prize_amount : '等待开奖') + '</td>';
		}
		tr      += '	<td style="font-size: 12px;line-height:12px;">' + v.date_createtime + '</td>';
		tr      += '	<td style="font-size:12px;"><a href="javascript:void(0);" href="javascript:void(0);" href="javascript:void(0);" class="alink tag_see_more" amv="' + v.id + '">查看</a></td>';
		
		tr 		+= '</tr>';
		$('#id_record_list').prepend(tr);
		bet_all_money += parseFloat(v.bet_money);
		winner_money_amount += parseFloat(v.prize_amount);
		item_index++;
	})
	createPage(np, item_index);
	$('#id_summary span').eq(0).html(bet_all_money + '元');
	$('#id_summary span').eq(1).html(winner_money_amount + '元');
	$('#id_summary span').eq(2).html(parseFloat(winner_money_amount-bet_all_money).toFixed(2) + '元');
}

/**
 * np: 当前页面
 */
function createPage(np='', allNums=''){
	if(!np){
		np       = $('#id_page_box li[class="tag_page_item active"]').attr('ami');
	}
	np           = np ? parseInt(np) : 1;
	var pageNums = parseInt(allNums/page_limit);
	if((parseInt(allNums)%page_limit) > 0) {
		pageNums++;
	}
	// 如果小于1， 则不需要分页数据
	if(pageNums < 1) {
		$('#id_page_box').html('');
		return;
	}
	var pageHtml      = '';
	var firstPageHtml = '<li class="tag_first_page"><a href="javascript:void(0);" href="javascript:void(0);" href="javascript:void(0);">第一页</a></li>';
	var upPageHtml    = '<li class="tag_up_page"><a href="javascript:void(0);" href="javascript:void(0);">上一页</a></li>';
	var downPageHtml  = '<li class="tag_down_page"><a href="javascript:void(0);" href="javascript:void(0);">下一页</a></li>';
	var endPageHtml   = '<li class="tag_end_page"><a href="javascript:void(0);" href="javascript:void(0);">最后一页</a></li>';
	var pageChoice    = '';
	var i     = 1;
	times     = 5;
	if(pageNums < times) times = pageNums;
	if(np > 3){
		// 标签标识往后移
		i = np - 2;
		// 检查是否到最后一页了
		if((np + 2) < pageNums){
			times = np + 2;
		}else{
			times = pageNums;
		}
	}
	
	for(i; i <= times; i++){
		pageChoice   = '';
		if(np == i) pageChoice = 'active';
		pageHtml += '<li ami="' + i + '" class="tag_page_item ' + pageChoice + '"><a href="javascript:void(0);" href="javascript:void(0);">' + i + '</a></li>';
	}
	$('#id_all_rows').html(allNums);
	// 当前循环没有数据，不做分页构造
	$('#id_page_box').html(firstPageHtml + upPageHtml + pageHtml + downPageHtml + endPageHtml);
	$('#id_page_box').show();
}

function showMsg(title, content){
	layer.open({
        title: title,
        content: content,
        className: 'layui-m-tag-msg',
        btn: ['确定'],
        yes: function (index){
			// 继续投注
        	layer.close(index);
        },
    });
}
